package com.cloudbroker.bcs.common.util;

public class OrderNumberUtil {
    
    public static final int LENGTH = 11;
    
    public static String encode(Long brokerId) {
        String s = Long.toString(brokerId, Character.MAX_RADIX);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < LENGTH - s.length(); i++) {
            sb.append('0');
        }
        sb.append(s);
        return sb.toString();
    }
    
    public static Long decode(String encrypted) {
        int j = 0;
        for (int i = 0; i < encrypted.length(); i++) {
            if ('0' != encrypted.toCharArray()[i]) {
                j = i;
                break;
            }
        }
        encrypted = encrypted.substring(j);
        return Long.parseLong(encrypted, Character.MAX_RADIX);
    }
    
    public static void main(String[] args) {
        String s = OrderNumberUtil.encode(1012380000000000005l);
        System.out.println(s);
        System.out.println(OrderNumberUtil.decode(s));
    }
}
